//index.js
//获取应用实例
import {request,post} from "../../request/index.js"
const app =getApp()
Page({
  data: {
    id:"",
    motto: 'Hello World',
    userInfo: {},
    photoList:[],
    hasUserInfo: false
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function (option) {
  //  const uid = wx.getStorageSync('uid');
  //   if (undefined!=uid&&""!=uid) {
  //     if (undefined!=uid&&""!=uid) {
  //       this.getUserInfo(uid)
  //       this.getUserLifePhoto(uid)
  //     } 
  //   } 
  },
  onShow:function(){
    const uid = wx.getStorageSync('uid');
    if (undefined!=uid&&""!=uid) {
      this.getUserInfo(uid)
      this.getUserLifePhoto(uid)
    } 
  },

  getUserLifePhoto(uid){
    let user = {userId:uid};
    post({url:app.globalData.baseUrl+"sys_member_rel_photo/list",data:user}).then(result=>{
      const res = result.data;
      if(res.code!=0){
       }else{
         this.setData({photoList:res.data})
       }
    })
  },

  getUserInfo(id) {
    request({url:app.globalData.baseUrl+"sys_member/"+id}).then(result=>{
       this.setData({userInfo:result.data.data})
    })
  },
  previewImg: function (e) {
    //获取当前图片的下标
    var index = e.currentTarget.dataset.index;
    //所有图片
    var imgs = this.data.photoList;
    let photoUrls = [];
    for(let i =0;i<imgs.length;i++){
      photoUrls.push(imgs[i].url);
    }
    wx.previewImage({
      //当前显示图片
      current: photoUrls[index],
      //所有图片
      urls: photoUrls
    })
  },
})
